<template>
  <common-layout>
    <div class="top">
      <div class="header">
        <img alt="logo" class="logo" src="@/assets/img/logo.png" />
        <span class="title">儿科渠道注册</span>
      </div>
    </div>
    <div class="login">
      <a-tabs
        size="large"
        :tabBarStyle="{ textAlign: 'center' }"
        style="padding: 0 2px"
        default-active-key="1"
      >
        <a-tab-pane tab="注册账号" key="1">
          <a-form
            :form="form"
            :label-col="{ span: 6 }"
            :wrapper-col="{ span: 16 }"
            @submit="handleSubmit"
          >
            <a-form-item label="商户编号" hidden>
              <a-input v-decorator="['disbNO']" />
            </a-form-item>
            <a-form-item label="注册类型">
              <a-radio-group
                v-decorator="[
                  'distype',
                  {
                    initialValue: '个人注册',
                    rules: [
                      {
                        required: true,
                        message: '请选择注册类型',
                        whitespace: true,
                      },
                    ],
                  },
                ]"
                @change="handleRadio"
              >
                <a-radio value="个人注册"> 个人注册 </a-radio>
                <a-radio value="医生注册"> 医生注册 </a-radio>
              </a-radio-group>
            </a-form-item>
            <a-form-item>
              <span slot="label">
                渠道&nbsp;
                <a-tooltip title="填写所属团体，协会，医院或学会">
                  <a-icon type="question-circle-o" />
                </a-tooltip>
              </span>
              <a-input v-decorator="['channel']" />
            </a-form-item>
            <a-form-item>
              <span slot="label">
                上级编号&nbsp;
                <a-tooltip title="所属上级的编码">
                  <a-icon type="question-circle-o" />
                </a-tooltip>
              </span>
              <a-input v-decorator="['superiorNumber']" />
            </a-form-item>
            <div v-if="hideDocFormItem">
              <a-form-item label="所属医院">
                <a-input v-decorator="['hospital']" />
              </a-form-item>
              <a-form-item label="所属科室">
                <a-input v-decorator="['department']" />
              </a-form-item>
            </div>
            <a-form-item label="姓名">
              <a-input
                v-decorator="[
                  'disbName',
                  {
                    rules: [
                      {
                        required: true,
                        message: '请输入姓名',
                        whitespace: true,
                      },
                    ],
                  },
                ]"
              />
            </a-form-item>
            <a-form-item label="手机号">
              <a-input
                v-decorator="[
                  'mobile',
                  {
                    rules: [
                      {
                        required: true,
                        message: '请输入手机号',
                        whitespace: true,
                      },
                    ],
                  },
                ]"
              />
            </a-form-item>
            <a-form-item label="初始密码">
              <a-input-password
                v-decorator="[
                  'password',
                  {
                    rules: [
                      {
                        required: true,
                        message: '请输入初始密码',
                        whitespace: true,
                      },
                    ],
                  },
                ]"
              />
            </a-form-item>
            <div class="buttonBox">
              <a-button @click="handleSubmit" type="primary">提交</a-button>
              <a-button @click="handleBack" type="danger">返回</a-button>
            </div>
          </a-form>
        </a-tab-pane>
      </a-tabs>
    </div>
  </common-layout>
</template>

<script>
// 账号15961858835
// 密码 123456
// 账号18362375700
// 密码 234567

import CommonLayout from "@/layouts/CommonLayout";
import { addDis, getTreeData } from "../../services/dataSource";
import axios from "axios";
import { mapMutations } from "vuex";

export default {
  name: "Login",
  components: { CommonLayout },
  data() {
    return {
      form: this.$form.createForm(this),
      hideDocFormItem: false,
      defaultRadio: "1",
    };
  },
  computed: {},
  methods: {
    //选择个人注册和医生注册
    handleRadio({ target }) {
      if (target.value == "医生注册") {
        this.hideDocFormItem = true;
      } else {
        this.hideDocFormItem = false;
      }
    },
    handleBack() {
      this.$router.push("/login");
    },
    handleSubmit(e) {
      e.preventDefault();
      this.form.validateFields((err, values) => {
        if (!err) {
          addDis(values).then((res) => {
            if (res.data.success == true) {
              this.$message.success("注册成功，请返回登录！");
            } else {
              this.$message.error("注册失败，请重试！");
            }
          });
        }
      });
    },
  },
  created() {},
};
</script>

<style lang="less" scoped>
.common-layout {
  .top {
    text-align: center;
    margin-top: 1.125rem;
    .header {
      height: 44px;
      line-height: 44px;
      a {
        text-decoration: none;
      }
      .logo {
        height: 44px;
        vertical-align: top;
        margin-right: 16px;
      }
      .title {
        font-size: 33px;
        color: @title-color;
        font-family: "Myriad Pro", "Helvetica Neue", Arial, Helvetica,
          sans-serif;
        font-weight: 600;
        position: relative;
        top: 2px;
      }
    }
    .desc {
      font-size: 14px;
      color: @text-color-second;
      margin-top: 12px;
      margin-bottom: 40px;
    }
  }
  .login {
    width: 400px;
    margin: 20px auto;
    font-size: 16px;
    background: #fff;
    @media screen and (max-width: 576px) {
      width: 95%;
    }
    @media screen and (max-width: 320px) {
      .captcha-button {
        font-size: 14px;
      }
    }
    .icon {
      font-size: 24px;
      color: @text-color-second;
      margin-left: 16px;
      vertical-align: middle;
      cursor: pointer;
      transition: color 0.3s;

      &:hover {
        color: @primary-color;
      }
    }
  }
}
.ant-input {
  padding-left: 40px;
}
.buttonBox{
  display: flex;
  justify-content: space-between;
  margin:10px 25px
}
</style>
